#ifndef RenderModelLocal_h__
#define RenderModelLocal_h__

#include "RenderModel.h"

typedef inf::List<modelSurface_t>   ModelSurfaceList;

class RenderModelStatic: public RenderModel {
    friend class RenderWorldLocal;

public:
    RenderModelStatic();
    ~RenderModelStatic();

    void            InitFromFile( const char* fileName );
    const char*     GetName() const;
    void            TouchData();

    bool            IsLoaded() const;
    void            LoadModel();

    void            PurgeModel();

    void            AddSurface( modelSurface_t& surface );
    void            FinishSurfaces();

    int             NumSurfaces() const;
    modelSurface_t* GetSurface( int index );

    srfTriangles_t* AllocSurfaceTriangles( int numVerts, int numIndexes );
    void            FreeSurfaceTriangles( srfTriangles_t* srf );

    inf::Bounds     Bounds( const renderEntity_s* ent = NULL );
protected:
    inf::Str            name;

    inf::Str            filePathName;

    ModelSurfaceList    surfaces;
    inf::Bounds         bounding;

    bool                purged;

    unsigned int*   glBufVtxIds;
    unsigned int*   glBufIdxIds;
};

/*
===============================================================================

	ASE loader. (3D Studio Max ASCII Export)

===============================================================================
*/

typedef struct {
	int						vertexNum[3];
	int						tVertexNum[3];
	inf::Vec3					faceNormal;
	inf::Vec3					vertexNormals[3];
	inf::byte					vertexColors[3][4];
} aseFace_t;

typedef struct {
	int						timeValue;

	int						numVertexes;
	int						numTVertexes;
	int						numCVertexes;
	int						numFaces;
	int						numTVFaces;
	int						numCVFaces;

	inf::Vec3					transform[4];			// applied to normals

	bool					colorsParsed;
	bool					normalsParsed;
	inf::Vec3 *				vertexes;
	inf::Vec2 *				tvertexes;
	inf::Vec3 *				cvertexes;
	aseFace_t *				faces;
} aseMesh_t;

typedef struct {
	char					name[128];
	float					uOffset, vOffset;		// max lets you offset by material without changing texCoords
	float					uTiling, vTiling;		// multiply tex coords by this
	float					angle;					// in clockwise radians
} aseMaterial_t;

typedef struct {
	char					name[128];
	int						materialRef;

	aseMesh_t				mesh;

	// frames are only present with animations
	inf::List<aseMesh_t*>		frames;			// aseMesh_t
} aseObject_t;

typedef struct aseModel_s {
	//ID_TIME_T					timeStamp;
	inf::List<aseMaterial_t *>	materials;
	inf::List<aseObject_t *>	objects;
} aseModel_t;


aseModel_t *ASE_Load( const char *fileName );
void		ASE_Free( aseModel_t *ase );

class RenderModel_ase: public RenderModelStatic {
public:
    RenderModel_ase();
    ~RenderModel_ase();

    void            InitFromFile( const char* fileName );
    void            TouchData();
    void            LoadModel();
protected:
    bool            ConvertASEToModelSurfaces( aseModel_t* ase );
};

struct aiScene;
struct aiNode;

class RenderModel_assimp: public RenderModelStatic {
public:
    RenderModel_assimp();
    ~RenderModel_assimp();

    void            InitFromFile( const char* fileName );
    void            TouchData();
    void            LoadModel();
protected:

    void            ImportModels_Recursive( const aiScene* scene, const aiNode* node );

};
#endif // RenderModelLocal_h__